<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="/common/common.jspf"%>
    <script type="text/javascript" src="${ctx}/js/qc/nc/nc_add.js">

    </script>
    <style type="text/css">
        .col-sm-3 {
            width: 15%;
            float: left;
        }

        .col-sm-9 {
            width: 35%;
            float: left;
        }

        label[class^="btn btn-default"] {
            margin-top: -4px;
        }
    </style>
</head>
<body>
<div class="l_err" style="width: 100%; margin-top: 2px;"></div>
<form id="form" name="form" class="form-horizontal" method="post"
      action="${ctx}/devicefault/devicefault_editEntity.shtml">
    <input type="hidden" value="${user.devicegl}" name="deviceFaultFormMap.devicegl" id="devicegl">
    <input type="hidden" value="${user.deviceFaultId}" name="deviceFaultFormMap.deviceFaultId" id="deviceFaultId">
    <section class="panel panel-default">
        <div class="panel-body">
            <div class="form-group">
                <label class="col-sm-3 control-label">设备名称</label>
                <div class="col-sm-9">
                    <input type="text" class="form-control checkabh" name="deviceFaultFormMap.deviceName" id="deviceName" value="${user.deviceName}" readonly="readonly" >
                    <%--<input type="button" class="btn btn-default" onclick="addAccount()" style="position: absolute; top: -1px; left: 230px;" value="按钮"/>--%>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">计划名称</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control checkabh" name="deviceFaultFormMap.devicepan" id="devicepan" value=" ${user.devicepan}" readonly="readonly">

                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">计划开始时间</label>
                <div class="col-sm-9">
                    <input type="date" class="form-control checkabh" name="deviceFaultFormMap.deviceFaultDate" id="deviceFaultDate" value="${user.deviceFaultDate}" readonly="readonly" >
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">计划结束时间</label>
                    <div class="col-sm-9">
                        <input type="date" class="form-control checkabh" name="deviceFaultFormMap.deviceend" id="deviceend" value="${user.deviceend}" readonly="readonly" >
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">周期类型</label>
                <div class="col-sm-9">
                    <select class="form-control" name="deviceFaultFormMap.devicecycletype" id="devicecycletype" readonly="readonly"  >
                        <c:choose>
                            <c:when test="${user.devicecycletype eq '日'}">
                                <option value="日" selected>日</option>
                                <option value="周">周</option>
                                <option value="月">月</option>
                            </c:when>
                            <c:when test="${user.devicecycletype eq '周'}">
                                <option value="日">日</option>
                                <option value="周" selected>周</option>
                                <option value="月">月</option>
                            </c:when>
                            <c:when test="${user.devicecycletype eq '月'}">
                                <option value="日">日</option>
                                <option value="周">周</option>
                                <option value="月" selected>月</option>
                            </c:when>
                        </c:choose>
                    </select>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">周期</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control checkabh" name="deviceFaultFormMap.devicecycle" id="devicecycle" value="${user.devicegl}" readonly="readonly">
                    </div>
                </div>
            </div>

            <%--<!-- 开始处理清单 -->--%>
            <%--<div class="panel panel-default">--%>
                <%--<div class="panel-heading">--%>
                    <%--<h3 class="panel-title">保养项目</h3>--%>
                <%--</div>--%>
                <%--<div class="panel-body">--%>
                    <%--<table class="table table-bordered" >--%>
                        <%--<thead>--%>
                        <%--<tr>--%>
                            <%--<th style="text-align: center; width:135px;">所属部位</th>--%>
                            <%--<th style="text-align: center; width:135px;">项目描述</th>--%>
                            <%--<th><input type="button" class="btn btn-primary" onclick="insert_row(this)" value="增加"></th>--%>
                        <%--</tr>--%>
                        <%--</thead>--%>
                        <%--<tbody id="tbl">--%>

                        <%--<c:forEach items="${bom}" var="do_bom">--%>
                            <%--<tr>--%>
                                <%--<td>--%>
                                    <%--<div class="input-group" style="width: 100px;">--%>
                                        <%--<input type="text" class="form-control" name="ly_dev_part" id="ly_dev_part"  value="${do_bom.ly_dev_part}"> <span class="input-group-btn"></span>--%>
                                    <%--</div>--%>
                                <%--</td>--%>
                                <%--<td>--%>
                                    <%--<div class="input-group">--%>
                                        <%--<input type="text" class="form-control"--%>
                                               <%--name="ly_dev_describe" id="ly_dev_describe" value="${do_bom.ly_dev_describe}">--%>
                                    <%--</div>--%>
                                <%--</td>--%>

                                <%--<td><input type="button" class="btn btn-danger" onclick ="deleteRow(this)" value ="删除"></td>--%>
                            <%--</tr>--%>
                        <%--</c:forEach>--%>


                        <%--</tbody>--%>
                    <%--</table>--%>
                <%--</div>--%>
            <%--</div>--%>


            <c:set value="${deviceIdArr}" var="deviceIdArr"/>
            <c:set value="${deviceNameArr}" var="deviceNameArr"/>
            <c:set value="${panelArr}" var="panelArr"/>
            <c:set value="${partList}" var="partList"/>
            <c:set value="${DeviceFaultDetailList}" var="DeviceFaultDetailList"/>
            <!-- 开始处理清单 -->
            <div id = "deviceInfo">
                <%--隐藏的数据，用于向后台传递panel下标列表--%>
                <input type="text" style="display:none;" value="${panelStr}" name="panelNum" id="panelNum">
                    <%--<c:forEach items="${deviceIdArr}" var="deviceId" varStatus="xh">--%>
                    <c:forEach items="${DeviceFaultDetailList}" var="DeviceFaultDetail" varStatus="xh">
                        <div class="panel panel-default" id="divId${xh.index}">
                            <div class="panel-heading">
                                <h3 class="panel-title">名称 :  <c:out value="${deviceNameArr[xh.index]}"/>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                编码 :  <c:out value="${deviceIdArr[xh.index]}"/>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <span>
                                    <%--<input type="button" class="btn btn-danger" onclick ="deletePanel(${panelArr[xh.index]},${deviceIdArr[xh.index]},${deviceNameArr[xh.index]})" value ="删除">--%>
                                <span>
                                </h3>
                                <%--用于记录设备关联的部位下标--%>
                                <input type="text" style="display:none;" class="form-control checkabh" value="${partList[xh.index]}" name="partSn${xh.index}" id="partSn${xh.index}">
                                <%--//用于记录设备的名称--%>
                                <input type="text" value="${deviceNameArr[xh.index]}" style="display:none;" class="form-control checkabh" name="deviceName${xh.index}" id="deviceName${xh.index}">
                                <%--//用于记录设备的id--%>
                                <input type="text" value="${deviceIdArr[xh.index]}" style="display:none;" class="form-control checkabh" name="deviceId${xh.index}" id="deviceId${xh.index}">
                            </div>
                            <div class="panel-body">
                                <table class="table table-bordered" >
                                    <thead>
                                    <tr>
                                        <th style="text-align: center; width:135px;">所属部位</th>
                                        <th style="text-align: center; width:135px;">保养描述</th>
                                        <%--<th><input type="button" class="btn btn-primary" onclick="insert_rows(' + panelNum + ')" value="增加"></th>--%>
                                        </tr>
                                    </thead>
                                    <tbody id="tb${panelArr[xh.index]}">
                                    <%--保养部位循环部分--%>
                                    <c:forEach items="${DeviceFaultDetail}" var="DeviceFault" varStatus="num">
                                        <%--<c:if test="${DeviceFault.deviceCode == deviceId}">--%>
                                            <tr>
                                                <td>
                                                    <input type="text" class="form-control" name="ly_dev_part${panelArr[xh.index]}${num.index}" id="ly_dev_part${panelArr[xh.index]}${num.index}" value = "${DeviceFault.devMaintenancePartName}">
                                                </td>
                                                <td>
                                                    <input type="text" class="form-control" name="ly_dev_describe${panelArr[xh.index]}${num.index}" id="ly_dev_describe${panelArr[xh.index]}${num.index}" value = "${DeviceFault.descs}">
                                                </td>
                                            </tr>

                                        <%--</c:if>--%>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </c:forEach>
            </div>

        </div>
        <footer class="panel-footer text-right bg-light lter">
            <button type="submit" class="btn btn-success btn-s-xs">提交</button>
        </footer> </section>
</form>

<script type="text/javascript">

    $(function(){
        console.log([[${deviceIdArr}]]);
        console.log([[${deviceNameArr}]]);
        console.log([[${panelArr}]]);
        console.log([[${partList}]]);
    })





    function inser_data(data) {
        var name =  $("#deviceName").val();
        if(name==''||name==undefined||name==null ){
            $("#deviceName").val(data);
        }else {
            $("#deviceName").val(name +","+ data);
        }

    }


    var i = 0
    function insert_row(obj) {
        i++;
        R = tbl.insertRow(tbl.rows.length);
        C = R.insertCell(0);
        C.innerHTML = '<div class="input-group"><input type="text" class="form-control" name="ly_dev_part"id="ly_dev_part'+i+'">'
            + '<span class="input-group-btn">'
            + '<span class="glyphicon glyphicon-search"></span></button></span></div>';
        C = R.insertCell(1);
        C.innerHTML = '<div class="input-group"><input type="text" class="form-control" name="ly_dev_describe" id="ly_dev_describe"></div>';
        C = R.insertCell(2);
        C.innerHTML = '<input type="button" class="btn btn-danger" onclick ="deleteRow(this)" value ="删除">';
    }
    //打开一个新页面
    function addAccount() {
        pageii = layer.open({
            title : "新增设备",
            type : 2,
            area : [ "600px", "60%" ],
            content : rootPath + '/devicefault/facility.shtml'
        });
    }
    function deleteRow(obj) {
        var i = obj.parentNode.parentNode.rowIndex;
        if (i > 0) {
            tbl.deleteRow(i-1);
        }
    }
</script>
</body>
</html>